package com.atech.ace.web.cart;

import java.util.LinkedHashMap;
import java.util.Map;

import com.atech.ace.entity.Product;
import com.atech.ace.entity.User;

public class ShoppingCart {

	private String uniqueId;
	private User user;
	private Map products;
	
	public ShoppingCart()
	{
		this.uniqueId = String.valueOf(System.currentTimeMillis());
		this.products = new LinkedHashMap();
		
	}
	
	public ShoppingCart(String uniqueId)
	{
		this.uniqueId = uniqueId;
		this.products = new LinkedHashMap();
	}

	public void addOrUpdateProduct(Product p)
	{
		Product added = ( Product ) products.get(p.getProductId());
		if(added != null)
		{
			added.setCurrentQuantity(p.getCurrentQuantity());
		}
		else
		{
			products.put(p.getProductId(), p);
		}
	}
	
	public void removeProduct(Product p)
	{
		products.remove(p);
	}
	
	
	
	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Map getProducts() {
		return products;
	}

	public void setProducts(Map products) {
		this.products = products;
	}
	
	
	
}
